// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    opacity: 0,
    scrollTop: 0,
    height: "",
    tabHeight: "",
    background: '/images/home/bg.png',
    showBg: true,
    cardList: [{
        id: 1,
        icon: '/images/home/card_one/1.png',
        text: '我的项目',
        // path: '/pages/myProject/myProject'
      },
      {
        id: 2,
        icon: '/images/home/card_one/2.png',
        text: '设备管理',
        path: '/pages/management/management'
      },
      {
        id: 3,
        icon: '/images/home/card_one/3.png',
        text: '财务数据',
        path: '/pages/financial/financial'
      },
      {
        id: 4,
        icon: '/images/home/card_one/4.png',
        text: '经营分析',
        path: '/pages/analysis/analysis'
      },
      {
        id: 5,
        icon: '/images/home/card_one/5.png',
        text: '用户消息',
        path: '/pages/message/message'
      },
      // {
      //   id: 6,
      //   icon: '/images/home/card_one/6.png',
      //   text: '设备警报',
      //   badge: 1
      // },
    ],
    cardTwoList: [{
        id: 1,
        icon: '/images/home/card_two/1.png',
        text: '广告设置'
      }, {
        id: 2,
        icon: '/images/home/card_two/2.png',
        text: '秒杀活动'
      },
      {
        id: 3,
        icon: '/images/home/card_two/3.png',
        text: '场地险',
        isNew: true
      }
    ]
  },
  clickItem(event) {
    // if (!this.data.token) {
    //   wx.navigateTo({
    //     url: "/pages/login/login",
    //   });
    //   return;
    // }
    const {
      url
    } = event.currentTarget.dataset;
    console.log("url: ", url);
    if (url) {
      wx.navigateTo({
        url,
      });
    } else {
      wx.showToast({
        title: '敬请期待',
        icon:'none'
      })
    }
  },
  initHeight() {
    const res = wx.getSystemInfoSync();
    const {
      screenHeight,
      safeArea: {
        bottom
      },
    } = res;
    console.log("resHeight", res);
    if (screenHeight && bottom) {
      let safeBottom = screenHeight - bottom;
      this.setData({
        tabHeight: 48 + safeBottom,
      });
    }
  },
  //监听屏幕滚动 判断上下滚动
  onPageScroll: function (ev) {
    console.log(ev)
    let _this = this;
    _this.setData({
      scrollTop: ev.scrollTop
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initHeight();
    // 展示本地存储能力
    var token = wx.getStorageSync("token") || "";
    let res = wx.getSystemInfoSync(); ///微信api方法
    let titleH;
    if (res && res["system"]) {
      // 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
      if (res["system"].indexOf("Android") > 0) {
        titleH = 48;
      } else {
        titleH = 44;
      }
      var height = titleH + res["statusBarHeight"];
      console.log(height, "height");
      this.setData({
        height: height,
        token: token,
      });
    }
    if (token) {
      console.log("onLoad第一次进入页面", token);
      setTimeout(() => {
        // this.getActiveInfo();
        // this.getCurrentAct();
      }, 500);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})